{block name="main"}
<!-- page -->
{if $page_status}
<div class="panel-detail">
    <div class="item">
        <div class="media">
            <div class="media-left">
                <img src="" width="160px" height="160px" id="user_headimg" >
            </div>
            <div class="media-body">
                <p class="p">昵称：<span id="nick_name"></span></p>
                <p class="p">姓名：<span id="channel_real_name"></span></p>
                <p class="p">手机号码：<span id="channel_p"></span></p>
                <p class="p">下级渠道商：<span class="text-bright" id="channel_number"></span>人</p>
            </div>
        </div>
    </div>
</div>
{/if}

<form class="v-filter-container">
    <div class="filter-fields-wrap">
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label">会员信息</label>
                    <div class="v__controls">
                        <input type="text" id="name" class="v__control_input" autocomplete="off">
                    </div>
                </div>

                <div class="v__control-group">
                    <label class="v__control-label">手机</label>
                    <div class="v__controls">
                        <input type="text" id="channel_phone" class="v__control_input" autocomplete="off">
                    </div>
                </div>

                <div class="v__control-group">
                    <label class="v__control-label">渠道商等级</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="channel_grade">
                            <option value="">请选择等级...</option>
                            {foreach name="channel_grade_list" item="value"}
                            <option value="{$value.channel_grade_id}">{$value.channel_grade_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {if $page_status}
                <div class="v__control-group">
                    <label class="v__control-label">渠道商状态</label>
                    <div class="v__controls">
                        <select class="v__control_input" id="status">
                            <option value="">请选择状态...</option>
                            <option value="0">未审核</option>
                            <option value="1">已审核</option>
                            <option value="-1">审核不通过</option>
                        </select>
                    </div>
                </div>
                {/if}

            </div>
        </div>
        <div class="filter-item clearfix">
            <div class="filter-item__field">
                <div class="v__control-group">
                    <label class="v__control-label"></label>
                    <div class="v__controls">
                        <a class="btn btn-primary search"><i class="icon icon-search"></i> 搜索</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<div class="screen-title">
    <span class="text">信息列表</span>
</div>
{if !$page_status}
<ul class="nav nav-tabs v-nav-tabs fs-12" data-type="uncheck" id="check_now_time">
    <li role="presentation" class="active" data-status="2"><a href="javascript:;" class="flex-auto-center channel_status">全部<span class="J-all">({$channel_count['all_count']})</span></a></li>
    <li role="presentation" class="" data-status="1"><a href="javascript:;" class="flex-auto-center channel_status">已审核<span class="J-all">({$channel_count['checked_count']})</span></a></li>
    <li role="presentation" class="" data-status="0"><a href="javascript:;" class="flex-auto-center channel_status">待审核<span class="J-all">({$channel_count['uncheck_count']})</span></a></li>
    <li role="presentation" class="" data-status="-1"><a href="javascript:;" class="flex-auto-center channel_status">审核不通过<span class="J-all">({$channel_count['nocheck_count']})</span></a></li>
    <!--默认是2展示出所有的渠道商-->
    <input type="hidden" id="search_status" value="2">
</ul>
{/if}
<table class="table v-table table-auto-center">
    <thead>
    <tr>
        <th>渠道商</th>
        <th>会员信息</th>
        <th>手机号码</th>
        <th>渠道等级</th>
        <th>状态</th>
        <th class="col-md-2 pr-14 operationLeft">操作</th>
    </tr>
    </thead>
    <tbody id="list">




    </tbody>
</table>
<input type="hidden" id="page_index" value="">
<nav aria-label="Page navigation" class="clearfix">
    <ul id="page" class="pagination pull-right"></ul>
</nav>

<!-- page end -->
{/block}
{block name="script"}
<script>
    require(['util'],function(util){
        util.initPage(getList);
        function getList(page_index){
            $("#page_index").val(page_index);
            var channel_phone = $("#channel_phone").val();
            var name = $("#name").val();
            var channel_grade = $("#channel_grade").val();
            var status = $('#search_status').val();
            var channel_id = '{$channel_id}';
            var uid = '{$uid}';
            var check_status = $('#status').val();
            $.ajax({
                type : "post",
                url : '{$channelList}',
                async : true,
                data : {
                    "page_index" :page_index, "channel_phone" : channel_phone, "name" : name, "channel_grade" : channel_grade, "status" : status, "channel_id" : channel_id, "uid" : uid, 'check_status':check_status
                },
                success : function(data) {
                    // console.log(data["channel_info"]);return;
                    var html = '';
                    if('{$page_status}'=='down' && data["channel_info"]){
                        if(data["channel_info"]['user_headimg']){
                            $('#user_headimg').attr('src',data["channel_info"]['user_headimg']);
                        }else{
                            $('#user_headimg').attr('src','/public/static/images/headimg.png');
                        }
                        $('#nick_name').html(data["channel_info"]['name']);
                        $('#channel_real_name').html(data["channel_info"]['channel_name']);
                        $('#channel_p').html(data["channel_info"]['channel_phone']);
                        $('#channel_number').html(data["channel_info"]['channel_num']);
                    }
                    if (data["data"].length>0) {
                        for (var i = 0; i < data["data"].length; i++) {
                            html += '<tr>';
                            if(data['data'][i]["user_headimg"]){
                                html += '<td><img src="' + data['data'][i]["user_headimg"] + '" width="30" height="30">';
                            }else{
                                html += '<td><img src="/public/static/images/headimg.png" width="30" height="30">';
                            }
                            if(data['data'][i]["nick_name"]){
                                html += '<td><span class="block">' + data['data'][i]["nick_name"] + '</span></td>';
                            }else{
                                html += '<td><span class="block">' + data['data'][i]["user_name"] + '</span></td>';
                            }
                            //手机号码
                            html += '<td><span class="block">' + data['data'][i]["user_tel"] + '</span></td>';
                            //渠道商等级
                            html += '<td><span class="block">' + data['data'][i]["channel_grade_name"] + '</span></td>';
                            //状态
                            if(data['data'][i]["status"] == 1){
                                html += '<td><span class="label label-green isexamine">已审核</span></td>';
                                html += '<td class="fs-0 operationLeft">' +
                                    '<a href="'+__URL('ADDONS_MAINchannelDetail&channel_id='+ data['data'][i]['channel_id']) +'" class="btn-operation isexamine">详情</a>' +
                                    '<a href="'+__URL('ADDONS_MAINpurchaseList&channel_id='+ data['data'][i]['channel_id']) +'&uid='+data['data'][i]['uid']+'" class="btn-operation isexamine">采购列表</a>' +
                                    '<a href="'+__URL('ADDONS_MAINdownChannelList&channel_id='+ data['data'][i]['channel_id']) +'&uid='+data['data'][i]['uid']+'&page_status=down" class="btn-operation isexamine">下级渠道商</a>' +
                                    '<a href="javascript:;" class="btn-operation remove" data-channel_id="'+ data["data"][i]['channel_id']+'">移除</a>' +
                                '</td>';
                            }else if(data['data'][i]["status"] == -1){
                                html += '<td><span class="label label-danger pass" data-type=1 data-channel_id="'+ data["data"][i]['channel_id']+'">审核未通过</span></td>';
                                html += '<td class="fs-0 operationLeft"><a href="javascript:;" class="btn-operation isexamine save" data-type=1 data-channel_id="'+ data["data"][i]['channel_id']+'">通过</a></td>';
                            }else{
                                html += '<td><span class="label label-orange pass" data-type=1 data-channel_id="'+ data["data"][i]['channel_id']+'">待审核</span></td>';
                                html += '<td class="fs-0 operationLeft"><a href="javascript:;" class="btn-operation isexamine save" data-type=1 data-channel_id="'+ data["data"][i]['channel_id']+'">通过</a><a href="javascript:;" class="btn-operation isexamine save" data-type=-1 data-channel_id="'+ data["data"][i]['channel_id']+'">拒绝</a></td>';
                            }
                            //操作
                            if(data['data'][i]["status"] == 1){

                            }else{

                            }
                            html += '</tr>';
                        }
                    } else {
                        html += '<tr><td class="h-200" colspan="6">暂无符合条件的数据记录</td></tr>';
                    }
                    $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                    $("#list").html(html);
                }
            });
        }
        $('.search').on('click',function(){
            util.initPage(getList);
        });

        $('body').on('click','.save',function(){
            var status = $(this).data('type');
            var channel_id = $(this).data('channel_id');
            if(status==-1){
                util.alert('确定审核不通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$channelCheckStatus}",
                        data:{'channel_id':channel_id,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val()));
                            }else{
                                util.message(data["message"], 'danger', getList($("#page_index").val()));
                            }
                        }
                    });
                })
            }else{
                util.alert('确定审核通过？',function(){
                    $.ajax({
                        type : "post",
                        url : "{$channelCheckStatus}",
                        data:{'channel_id':channel_id,'status':status},
                        async : true,
                        success : function(data) {
                            if(data["code"] > 0 ){
                                util.message(data["message"], 'success', getList($("#page_index").val()));
                            }else{
                                util.message(data["message"], 'danger', getList($("#page_index").val()));
                            }
                        }
                    });
                })
            }
        })
        $('body').on('click','.pass',function(){
            var status = $(this).data('type');
            var channel_id = $(this).data('channel_id');
            $.ajax({
                type : "post",
                url : "{$channelCheckStatus}",
                data:{'channel_id':channel_id,'status':status},
                async : true,
                success : function(data) {
                    if(data["code"] > 0 ){
                        util.message(data["message"], 'success', getList($("#page_index").val()));
                    }else{
                        util.message(data["message"], 'danger', getList($("#page_index").val()));
                    }
                }
            });
        })
        $('body').on('click','.channel_status',function(){
            var status = $(this).parent().data('status');
            //实现点击某一个按钮，颜色就选中
            $(this).parent().addClass('active').siblings().removeClass('active');
            $('#search_status').val(status);
            getList($("#page_index").val())
        })

        $('body').on('click','.remove',function(){
            channel_id = $(this).data('channel_id');
            $.ajax({
                type : "post",
                url : "{$removeChannel}",
                data:{'channel_id':channel_id},
                async : true,
                success : function(data) {
                    if(data["code"] > 0 ){
                        util.message(data["message"], 'success', getList($("#page_index").val()));
                    }else{
                        util.message(data["message"], 'danger', getList($("#page_index").val()));
                    }
                }
            });
        })
    })
</script>
{/block}
